import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:get/get.dart';
import 'package:kq_flutter_core_widget/widgets/button/kq_ink_well.dart';
import 'package:kq_flutter_tv_widgets/resources/kq_theme_colors.dart';
import 'package:kq_flutter_tv_widgets/widgets/pullDown/pull_down_menu.dart';

class KqPullDownMenuPage extends StatefulWidget {
  const KqPullDownMenuPage({super.key});

  @override
  State<KqPullDownMenuPage> createState() => _KqPullDownMenuPageState();
}

class _KqPullDownMenuPageState extends State<KqPullDownMenuPage> {
  List list1 = [
    {'title': 'wode1', 'titleId': '1'},
    {'title': 'wode2', 'titleId': '2'},
    {'title': 'wode3', 'titleId': '3'},
    {'title': 'wode4', 'titleId': '4'},
    {'title': 'wode5', 'titleId': '5'},
    {'title': 'wode6', 'titleId': '6'},
    {'title': 'wode7', 'titleId': '7'},
    {'title': 'wode8', 'titleId': '8'},
    {'title': 'quanbu', 'titleId': '9'},
    {'title': 'wode11', 'titleId': '1'},
    {'title': 'wode22', 'titleId': '2'},
    {'title': 'wode33', 'titleId': '3'},
    {'title': 'wode44', 'titleId': '4'},
    {'title': 'wode55', 'titleId': '5'},
    {'title': 'wode66', 'titleId': '6'},
    {'title': 'wode77', 'titleId': '7'},
    {'title': 'wode88', 'titleId': '8'},
    {'title': 'quanbu9', 'titleId': '9'}
  ];

  List list2 = [
    {'title': 'wode21', 'titleId': '1'},
    {'title': 'wode22', 'titleId': '2'},
    {'title': 'wode23', 'titleId': '3'},
    {'title': 'wode24', 'titleId': '4'},
    {'title': 'wode261', 'titleId': '6'},
    {'title': 'wode271', 'titleId': '7'},
    {'title': 'wode281', 'titleId': '8'},
    {'title': 'quanbu2', 'titleId': '9'}
  ];

  bool isShowCustom = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        children: [
          Row(
            children: [
              Expanded(
                  child: Column(
                children: [
                  PullDownMenu(
                    isUseOverlay: true,
                    titleRender: (titleData, menuIndex) {
                      return titleData['title'];
                    },
                    menuItemRender: (index,item) {
                      return item['title'];
                    },
                    menuDataRender: (menuIndex) {
                      if (menuIndex == 0) {
                        return list1;
                      }
                      return list2;
                    },
                    isDataSame: ((item, compareItem) {
                      if (item['title'] == compareItem['title']) {
                        return true;
                      }
                      return false;
                    }),
                    menuCustomWidgetRender: (menuIndex, menuController) {
                      if (menuIndex == 1) {
                        return Column(
                          children: [
                            Row(
                              children: [
                                SizedBox(
                                  height: 50.r,
                                  child: KqInkWell(
                                    onTap: () {
                                      setState(() {
                                        isShowCustom = false;
                                      });
                                      menuController.resetPullDownState();
                                    },
                                    child: Container(
                                      color: Colors.blue,
                                      child: Text('按钮1'),
                                    ),
                                  ),
                                ),
                                SizedBox(
                                  height: 50.r,
                                  child: KqInkWell(
                                      onTap: () {
                                        setState(() {
                                          isShowCustom = true;
                                        });
                                        menuController.reloadLayoutMenList();
                                      },
                                      child: Container(
                                        color: Colors.yellow,
                                        child: Text('按钮2'),
                                      )),
                                )
                              ],
                            ),
                            isShowCustom
                                ? Container(
                                    width: 500,
                                    height: 300,
                                    color: Colors.black,
                                  )
                                : SizedBox()
                          ],
                        );
                      }
                      return null;
                    },
                    menuWidgetHeight: (menuIndex) {
                      if (menuIndex == 1) {
                        if (isShowCustom) {
                          return 500.r;
                        }
                        return 50.r;
                      }
                      return null;
                    },
                    initChosenData: const [
                      {'title': '我的', 'titleId': '1'},
                      {'title': '我的2', 'titleId': '2'},
                      {'title': '我的3', 'titleId': '3'},
                    ],
                    pullDownCallback: (item, menuIndex, menuController) {},
                    isShowCustomWidget: (int menuIndex) {
                      if (menuIndex == 1) {
                        return true;
                      }
                      return false;
                    },
                    aliveTimeSearch: (menuIndex) {
                      return false;
                    },
                  )
                ],
              )),
              Expanded(child: Container())
            ],
          )
        ],
      ),
    );
  }
}
